package com.sse.security;

import java.io.FileInputStream;
import java.io.FileOutputStream;

import com.sse.VO.CasaVO;
import com.sse.casa.simulacion.ManejadorCasa;
import com.sse.util.Security;

public class TestSecurity {
	public static void main(String[] args) {

		/* Generate a DSA signature */

		if (args.length != 1) {
			System.out.println("Usage: GenSig nameOfFileToSign");
		} else
			try {

				//Lee archivo con 8 bytes
				FileInputStream datafis = new FileInputStream(args[0]);
				byte[] data = new byte[datafis.available()];
				datafis.read(data);
				datafis.close();
				
				for (int i = 1; i < 51 ; i++){
					
					CasaVO vo = ManejadorCasa.obtenerCasa(i);
					
					System.out.println(vo.getDescripcion());
				
					byte[] prvKey = vo.getPrivateKey();
					
					System.out.println("LLave privada: " + prvKey);
					System.out.println("LLave privada: " + prvKey.toString().length());
					
					byte[] sign = Security.signData(data, prvKey);
					System.out.println(sign);
					// save the sign on file */				
					FileOutputStream signfos = new FileOutputStream("C:/SampleText/sign");
					signfos.write(sign);
					signfos.close();
					
					//Verifica la firma
					byte[] pubKey = vo.getPublicKey();
					System.out.println("LLave publica: " +pubKey);					
					System.out.println("...................Result validation:" + Security.verifySign(sign, data, pubKey));
				}
				
			} catch (Exception e) {
				e.printStackTrace();
			}
	}
	
}
